package com.atguigu.lease.admin.controller;

import com.atguigu.lease.admin.service.CityInfoService;
import com.atguigu.lease.admin.service.DistrictInfoService;
import com.atguigu.lease.admin.service.ProvinceInfoService;
import com.atguigu.lease.model.bean.CityInfo;
import com.atguigu.lease.model.bean.DistrictInfo;
import com.atguigu.lease.model.bean.ProvinceInfo;
import com.atguigu.lease.model.result.Response;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "省市区管理模块")
@RestController
@RequestMapping("/admin/region")
public class RegionController {
    @Autowired
    ProvinceInfoService provinceInfoService;
    @Autowired
    CityInfoService cityInfoService;
    @Autowired
    DistrictInfoService districtInfoService;
    ///admin/region/district/listByCityId
    @Operation(summary = "3、根据城市id查询城市下面所有的区县")
    @GetMapping("district/listByCityId")
    public Response<List<DistrictInfo>> listDistrictInfos(@RequestParam Long id){ //根据城市id查询区县列表
        List<DistrictInfo> districtInfos = districtInfoService.list(Wrappers.lambdaQuery(DistrictInfo.class)
                .eq(DistrictInfo::getCityId, id));
        return Response.ok(districtInfos);
    }
//    /admin/region/city/listByProvinceId
    @Operation(summary = "2、根据省id查询省下面所有的城市")
    @GetMapping("city/listByProvinceId")
    public Response<List<CityInfo>> listCities(@RequestParam Long id){ //根据省id查询城市列表
        List<CityInfo> cityInfos = cityInfoService.list(Wrappers.lambdaQuery(CityInfo.class)
                .eq(CityInfo::getProvinceId, id));
        return Response.ok(cityInfos);
    }
    @Operation(summary = "1、查询所有省")
    @GetMapping("/province/list")
    public Response<List<ProvinceInfo>> listProvinceInfos(){
        return Response.ok(provinceInfoService.list());
    }

}
